﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Data;

namespace Winnow.SharepointDesigner.Layouts.Winnow.SharepointDesigner
{
    public partial class Site : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            try
            {
                Guid webId = new Guid(Request.QueryString["WebId"]);

                using (SPWeb web = SPContext.Current.Site.RootWeb.Site.OpenWeb(webId))
                {

                    lblSiteName.Text = web.Title;
                    lnkUrl.Text = web.Url;
                    lnkUrl.NavigateUrl = web.Url;

                    //  lnkCreateUrl.Text = "Create";
                    // lnkCreateUrl.NavigateUrl = web.Url + "/_layouts/create.aspx";
                    grdLists.AutoGenerateColumns = false;
                    grdLists.DataSource = web.Lists;
                    grdLists.ShowHeader = false;
                    grdLists.DataBind();

                    grdSubSites.AutoGenerateColumns = false;
                    grdSubSites.DataSource = web.Webs;
                    grdSubSites.ShowHeader = false;
                    grdSubSites.DataBind();

                    //  grdPermissions.AutoGenerateColumns = false;

                  

                    SPRoleAssignmentCollection oRoleAssignments = web.RoleAssignments;
                    List<SPPrincipal> permissions = new List<SPPrincipal>();
                    foreach (SPRoleAssignment oRoleAssignment in oRoleAssignments)
                    {

                        // SPRoleType provide enumaration for finding all user roles like  Administrators, Designer, Contributors, Visitors

                        //check oRoleAssignment.RoleDefinitionBindings.Contains(objMainWeb.RoleDefinitions.GetByType(SPRoleType.Administrator)) value
                        //  if current role is FULL CONTROL/Administrators then it will return TRUE

                        permissions.Add(oRoleAssignment.Member);

                        // oPrincipal object which will return SPuser or SPGroup, depending on current object

                    }


                    grdPermissions.DataSource = permissions;
                  //  grdPermissions.ShowHeader = false;
                    grdPermissions.DataBind();

                }

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
    }
}
